package com.yigo.bsc.gateway.controller;

import com.yigo.bsc.api.dict.BscDictFeign;
import com.yigo.bsc.api.dict.command.CreateDictItemCmd;
import com.yigo.bsc.api.dict.command.CreateDictTypeCmd;
import com.yigo.bsc.api.dict.query.DictItemQuery;
import com.yigo.bsc.api.dict.resp.DictItemListResp;
import com.yigo.bsc.app.service.BscDictAppService;
import com.yigo.cuc.domain.dict.repo.DictRepo;
import com.yigo.framework.http.Q;
import com.yigo.framework.http.R;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author chenzl
 */
@RestController
public class BscDictController implements BscDictFeign {
    @Resource
    private BscDictAppService bscDictAppService;
    @Resource
    private DictRepo dictRepo;

    @Override
    public R createDictType(Q<CreateDictTypeCmd> q) {
        bscDictAppService.createDictType(q.getNonNullParams());
        return R.ok();
    }

    @Override
    public R createDictItem(Q<CreateDictItemCmd> q) {
        bscDictAppService.createDictItem(q.getNonNullParams());
        return R.ok();
    }

    @Override
    public R<List<DictItemListResp>> queryDictItemList(Q<DictItemQuery> q) {
        return R.ok(dictRepo.queryDictItemList(q.getNonNullParams()));
    }
}
